
import numpy as np

# ndarray.ndim用于返回数组的维数，等于秩
def fun1():
    a = np.arange(24)
    print(a.ndim)

    b = a.reshape(2, 4, 3)
    print(b.ndim)

# ndarray.shape表示数组的维度，返回一个元组，表示 "行数" 和 "列数"
def fun2():
    a = np.array([[1, 2, 3], [4, 5, 6]])
    print(a.shape)

# 调整数组大小
def fun3():
    a = np.array([[1, 2, 3], [4, 5, 6]])
    a.shape = (3, 2)
    print(a)

# reshape函数调整数组大小
def fun4():
    a = np.array([[1, 2, 3], [4, 5, 6]])
    b = a.reshape(3, 2)
    print(b)

# ndarray.itemsize以字节的形式返回数组中每一个元素的大小，占几个字节
def fun5():
    x = np.array([1, 2, 3, 4, 5], dtype=np.int8)
    print(x.itemsize)

    y = np.array([1, 2, 3, 4, 5], dtype=np.float64)
    print(y.itemsize)

# ndarray.flags返回ndarray对象的内存信息
def fun6():
    x = np.array([1, 2, 3, 4, 5])
    print(x.flags)

if __name__ == '__main__':
    fun6()